package com.woniu.inlet.web.controller;

import com.woniu.inlet.web.fo.ConfirmCurrentSellOrder;
import com.woniu.inlet.web.fo.ConfirmSellOrder;
import com.woniu.inlet.web.fo.FixedInputBuyOrder;
import com.woniu.inlet.web.vo.PayToOrderVo;
import com.woniu.service.CurrentService;
import com.woniu.service.FixedInputService;
import com.woniu.service.FundAndGoldService;
import com.woniu.service.OrderService;
import com.woniu.service.command.FixedOrCurrentBuyCommand;
import com.woniu.service.command.FundOrGoldBuyCommand;
import com.woniu.service.command.UpdateBuyStatusCommand;
import com.woniu.utils.ResultResponseUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(description = "微服务调用接口")
@Slf4j
@CrossOrigin
public class FeignController {

    @Autowired
    private CurrentService currentService;

    @Autowired
    private FixedInputService fixedInputService;

    @Autowired
    private OrderService orderService;

    @Autowired
    private FundAndGoldService fundService;

    @PostMapping("/order/fundOrGold/buy")
    @ApiOperation(value = "这是[基金fund]或[黄金gold]的购买方法-内部使用,仅供自测")
    public Object buyFundOrGold(@RequestBody PayToOrderVo fo){
        FundOrGoldBuyCommand command=new FundOrGoldBuyCommand(fo);
        command.execute();
        return true;
    }

    @PostMapping("/order/fixedOrCurrent/buy")
    @ApiOperation(value = "这是[定期fixed]或[活期current]理财的购买方法-内部使用,仅供自测")
    public Object buyFixedOrCurrent(@RequestBody PayToOrderVo fo){
        FixedOrCurrentBuyCommand command=new FixedOrCurrentBuyCommand(fo);
        command.execute();
        return true;
    }

    @ApiOperation("这是支付模块调用的方法,根据id来修改订单状态为已买入-内部使用,仅供自测")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderId",value = "订单id",required = true),
            @ApiImplicitParam(name = "buyCost",value = "手续费",required = true),
            @ApiImplicitParam(name = "buyShare",value = "购买份额",required = true)
    })
    @GetMapping("/order/updateStatus0To1")
    public Object updateStatus0To1(@RequestParam("orderId") Long orderId,
                                   @RequestParam("buyCost") String buyCost,
                                   @RequestParam("buyShare") Double buyShare){
        UpdateBuyStatusCommand command=new UpdateBuyStatusCommand(orderId,buyCost,buyShare);
        command.execute();
        return true;
    }

    @ApiOperation("得到卖出日期,用于判断是否可以[撤销]卖出-内部使用,仅供自测")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sId",value = "卖出的订单id",required = true),
            @ApiImplicitParam(name = "revocationDate",value = "卖出日期",required = true)
    })
    @PostMapping("/order/revocationDate")
    public void revocationDate(@RequestParam("sId") String sId,
                               @RequestParam("revocationDate") String revocationDate){
        fundService.addRevocation(sId,revocationDate);
    }

    @ApiOperation("基金和黄金卖出订单的确认-内部使用,仅供自测")
    @PostMapping("/order/confirmSellOrder")
    public void confirmSellOrder(@RequestBody ConfirmSellOrder confirmSellOrder){
        fundService.confirmSellOrder(confirmSellOrder);
    }

    @ApiOperation("活期卖出订单的确认-内部使用,仅供自测")
    @PostMapping("/order/confirmCurrentSellOrder")
    public void confirmCurrentSellOrder(@RequestBody ConfirmCurrentSellOrder currentSellOrder){
        currentService.confirmSellOrder(currentSellOrder);
    }

    @ApiOperation("定投产品的买入后确认【可撤销】时间-内部使用,仅供自测")
    @PostMapping("/order/fixedInputBuyOrder")
    public void fixedInputBuyOrder(@RequestBody FixedInputBuyOrder fixedInputBuyOrder){
        fixedInputService.confirmBuyOrder(fixedInputBuyOrder);
    }
}
